use serde::{Deserialize, Serialize};
use crate::models::list_response::ListResponse;

#[derive(Debug, Serialize, Deserialize)]
pub struct PageResponse<T> {
    #[serde(flatten)] // 将父类字段嵌套到当前结构体中
    pub list_response: ListResponse<T>,
    pub no: Option<i32>,
    pub size: Option<i32>,
    pub total: Option<u64>,
    pub total_page: Option<i32>,
}

impl<T> PageResponse<T> {
    pub fn new() -> Self {
        PageResponse {
            list_response: ListResponse::new(),
            no: None,
            size: None,
            total: None,
            total_page: None,
        }
    }

    pub fn with_pagination(no: i32, size: i32, total: u64, total_page: i32, data: Vec<T>) -> Self {
        PageResponse {
            list_response: ListResponse::with_list(data),
            no: Some(no),
            size: Some(size),
            total: Some(total),
            total_page: Some(total_page),
        }
    }
}
